<script setup>
  import axios from "axios";
  let selectedFile;
  const onFileChange = (event) => {
    selectedFile = event.target.files[0];
  };

  const uploadImage = async () => {
    if (!selectedFile) {
      console.error('未选择文件');
      return;
    }
    const formData = new FormData();
    formData.append('image', selectedFile);
    try {
      const response = await axios.post('http://localhost:8080/user/image', formData, {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      });
      console.log(response.data);
    } catch (error) {
      console.error(error);
    }
  };
</script>

<template>
  <div>
    <input type="file" @change="onFileChange">
    <button @click="uploadImage">上传</button>
  </div>
</template>

<style scoped>

</style>